package cn.com.code.design;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;

/**
 * @author zhengpei
 * @date 2021/10/24
 */
public class JDBCUtil {

  private static final Logger logger = LoggerFactory.getLogger(JDBCUtil.class);

  private static final String URL = "jdbc:mysql://127.0.0.1:3306/eval_energy";

  private static final String USER = "root";

  private static final String PASSWORD = "root";

  public static void main(String[] args) throws SQLException, ClassNotFoundException {
    // 1.加载驱动
    Class.forName("com.mysql.jdbc.Driver");

    // 2.获得数据库连接
    Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);

    //操作数据库
    Statement statement = connection.createStatement();

    ResultSet resultSet = statement.executeQuery("SELECT id,u_name FROM user_info");

    while (resultSet.next()) {
      logger.info("测试结果 姓名：{} 年龄：{}", resultSet.getString("u_name"),resultSet.getInt("id"));
    }

  }

}
